<!-- 赠送 -->
<script setup>
import { ref, reactive } from 'vue'
// props
const props = defineProps({
  show: {
    type: Boolean,
    required: true
  },
  data: {
    type: Array,
    default: () => []
  }
})
// emits
const emit = defineEmits(['close', 'confirm'])

// 数据
const data = reactive({
  phoneNo: '',
  info: {

  },
  showIptErr: false,
  inputErr: '',
  checked: false,
  showSureModal: false,
})
// 关闭弹窗
const close = () => {
  reset()
  emit('close')
}
// 还原初始数据
const reset = () => {
  data.phoneNo = ''
  data.info = {}
  data.showIptErr = false
  data.inputErr = ''
  data.checked = false
}
// 搜索好友
const search = () => {
  data.info = {}
  data.checked = false
  // 输入为空
  if (!data.phoneNo) {
    data.showIptErr = true
    data.inputErr = '请输入手机号'
    return
  }
  // 输入为空
  if (!/^1[3456789]\d{9}$/.test(data.phoneNo)) {
    data.showIptErr = true
    data.inputErr = '请输入正确的手机号'
    return
  }
  // 查询后台数据 
  if (data.phoneNo != '18356572445') {
    data.showIptErr = true
    data.inputErr = '未查找到相关人员'
  } else {
    // 搜索成功
    data.info = {
      imageUrl: '/static/images/default_avatar.png',
      name: 'Abgla',
      cellPhone: '18356572445'
    }
  }
}
// 显示赠送确认弹窗
const give = () => {
  data.showSureModal = true
}
// 确认赠送
const sureGive = () => {
  data.showSureModal = false
}
</script>
<script>
export default {
  options: { styleIsolation: "shared" },
};
</script>
<template>
  <!-- 弹窗-选择商品 -->
  <up-popup :show="props.show" :closeable="true" @close="close" :round="10">
    <view class="Give-module">
      <view class="title">
        <text>选择好友</text>
      </view>
      <!-- 内容 -->
      <view class="cnt">
        <!-- 输入框 -->
        <view class="input-box">
          <up-input type="number" v-model="data.phoneNo" :maxlength="11" :clearable="true"
            :color="data.showIptErr ? '#FF1F1F' : ''" border="bottom" placeholder="请输入手机号"
            @focus="data.showIptErr = false">
            <template #prefix>
              <text class="label">手机号</text>
            </template>
            <template #suffix>
              <up-button text="搜索" :disabled="false" type="primary" shape="circle" @click="search"></up-button>
            </template>
          </up-input>
          <view v-if="data.showIptErr" class="inputErr"><text>{{ data.inputErr }}</text></view>
        </view>
        <!-- 搜索结果 -->
        <view v-if="data.info.name" class="search-result">
          <up-radio-group v-model="data.checked" placement="column" inactiveColor="#666666" activeColor="#FFC870">
            <view class="search-result-box">
              <view class="left">
                <up-avatar :src="data.info.imageUrl" :size="58"></up-avatar>
                <view class="info">
                  <view class="name">
                    <text>{{ data.info.name }}</text>
                  </view>
                  <view class="cellPhone">
                    <text>{{ data.info.cellPhone }}</text>
                  </view>
                </view>
              </view>
              <up-radio label="" :name="true"></up-radio>
            </view>
          </up-radio-group>
        </view>
      </view>
      <!-- 底部栏 -->
      <view class="bottom-bar">
        <view class="content">
          <up-button text="确认" type="primary" :disabled="!data.checked" shape="circle" @click="give"></up-button>
        </view>
      </view>
      <!-- 确认赠送信息弹窗 -->
      <up-modal :show="data.showSureModal" width="540rpx" title="请确认赠送信息" confirmText="确认" cancelText="取消"
        :showCancelButton="true" cancelColor="#929397" confirmColor="#FF7A00" :asyncClose="true"
        contentTextAlign="center" @cancel="data.showSureModal = false" @confirm="sureGive">
        <view class="sure-give-modal">
          <view>接收人: XXX</view>
          <view>手机号码: 1732813823</view>
        </view>
      </up-modal>
    </view>
  </up-popup>
</template>

<style lang="scss" scoped>
.Give-module {
  height: 1088rpx;

  // 标题
  & .title {
    margin-top: 30rpx;
    font-weight: 500;
    font-size: 36rpx;
    color: #303133;
    text-align: center;
  }

  // 内容
  & .cnt {
    padding: 56rpx 44rpx;

    // 搜索模块
    &::v-deep .input-box {

      // 输入框
      & .u-input {
        border-bottom: 2rpx solid;
        border-image: linear-gradient(270deg, rgba(217, 217, 217, 0), rgba(217, 217, 217, 1), rgba(217, 217, 217, 0)) 2 2;

        & .u-input__content__prefix-icon {
          margin-right: 44rpx;

          & .label {
            margin-bottom: 8rpx;
            font-weight: 400;
            font-size: 32rpx;
            color: #838385;
          }
        }

        & .u-button {
          width: 144rpx;
          height: 64rpx;
          font-weight: 400;
          font-size: 32rpx;
          color: #FFFFFF;
          border: none;
          background: linear-gradient(266deg, #FFCC7A 0%, #FF9900 100%);
          border-radius: 142rpx;
        }
      }

      // 错误信息
      & .inputErr {
        margin-top: 16rpx;
        margin-left: 160rpx;
        font-weight: 400;
        font-size: 24rpx;
        color: #FF1F1F;
      }
    }

    // 搜索结果
    & .search-result {

      padding: 60rpx 20rpx;

      & .search-result-box {
        display: flex;
        align-items: center;
        justify-content: space-between;

        & .left {
          display: flex;
          align-items: center;

          & .info {
            margin-left: 20rpx;

            & .name {
              font-weight: 500;
              font-size: 32rpx;
              color: #333333;
            }

            & .cellPhone {
              margin-top: 8rpx;
              font-weight: 400;
              font-size: 28rpx;
              color: #81818A;
            }
          }
        }
      }

    }
  }

  // 底部栏
  & .bottom-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100vw;
    height: 172rpx;
    background: #FFFFFF;
    border-top: 1rpx solid #E9E9EB;

    &::v-deep .content {
      box-sizing: border-box;
      padding: 12rpx 40rpx;

      & .u-button {
        height: 88rpx;
        font-weight: 500;
        font-size: 32rpx;
        color: #FFFFFF;
        background: #FFA618;
        border-radius: 112rpx;
        border: none;
      }
    }
  }

  // 赠送弹窗文字
  & .sure-give-modal {
    margin-top: 20rpx;

    & view {
      font-weight: 400;
      font-size: 28rpx;
      color: #333333;
      line-height: 40rpx;
      text-align: center;
    }
  }
}
</style>